import React from 'react'
const defaultData: any = [
    {
        id: '1', pp: [
            {
                id: '1-1', children: [
                    { id: '1 - 1 - 1 ' }
                ]
            }
        ]
    },
    {
        id: '2', CSSCounterStyleRule: [
            {
                id: '2 - 1', children: [
                    { id: '2 - 1 - 1' }
                ]
            }
        ]
    },
    {
        id: '3', dd: [

        ]
    }
]
export default function index() {
    //  /* 递归数据 */
    //  function deepClone(obj: any) {
    //     let objClone: any = Array.isArray(obj) ? [] : {}
    //     for (let key in obj) {
    //       if (obj.hasOwnProperty(key)) {
    //         //判断obj子元素是否为对象，如果是，递归复制
    //         if (typeof obj[key] === "object") {
    //           objClone[key] = deepClone(obj[key])
    //         } else {
    //           //如果不是，简单复制
    //           objClone[key] = obj[key]
    //         }
    //       }
    //     }
    //     return objClone
    //   }

    const deepCopy = (val: any) => {
        var objData: any = [];
        for (var key in val) {
            console.log(typeof val[key], 'kkkk', val[key]);
            if (typeof val[key] === "object") {
                objData[key] = deepCopy(val[key]);
            } else {
                objData[key] = val[key];
            }

        }
        console.log(objData, 'dpy');

        return objData;
    }
    var res = deepCopy(defaultData);
    res[0].id = 'baba'
    console.log(res);
    console.log(defaultData, 'default');

    return (
        <div style={{ margin: '0 auto' }}>

            <h1>深拷贝数据</h1>

        </div>

    )
}
